#ifndef STRUCTINTERFACE_H
#define STRUCTINTERFACE_H

#include <QtNetwork>
#include <string>


#define COMMAND_SUCCESS                                     0x10    //命令成功完成
#define COMMAND_FAIL                                        0x01    //命令执行失败
#define MCU_RESET_ERROR                                     0x20    //CPU复位错误
#define CW_ON_ERROR                                         0x21    //打开CW错误
#define ANTENNA_MISSING_ERROR                               0x22    //天线未连接
#define WRITE_FLASH_ERROR                                   0x23    //写Flash错误
#define READ_FLASH_ERROR                                    0x24    //读Flash错误
#define SET_OUTPUT_POWER_ERROR                              0x25    //设置发射功率错误
#define TAG_INVENTORY_ERROR                                 0x31    //盘存标签错误
#define TAG_READ_ERROR                                      0x32    //读标签错误
#define TAG_WRITE_ERROR                                     0x33    //写标签错误
#define TAG_LOCK_ERROR                                      0x34    //锁定标签错误
#define TAG_KILL_ERROR                                      0x35    //灭活标签错误
#define NO_TAG_ERROR                                        0x36    //无可操作标签错误
#define INVENTORY_OK_BUT_ACCESS_FAIL                        0x37    //成功盘存但访问失败
#define BUFFER_IS_EMPTY_ERROR                               0x38    //缓存为空
#define ACCESS_OR_PASSWORD_ERROR                            0x40    //访问标签错误或访问密码错误
#define PARAMETER_INVALID                                   0x41    //无效的参数
#define PARAMETER_INVALID_WORDCNT_TOO_LONG                  0x42    //wordCnt参数超出范围
#define PARAMETER_INVALID_MEMBANK_OUT_OF_RANGE              0x43    //MemBank参数超出范围
#define PARAMETER_INVALID_LOCK_REGION_OUT_OF_RANGE          0x44    //Lock数据区参数超出范围
#define PARAMETER_INVALID_LOCK_ACTION_OUT_OF_RANGE          0x45    //LockType参数超出范围
#define PARAMETER_READER_ADDRESS_INVALID                    0x46    //读写器地址无效
#define PARAMETER_INVALID_ANTENNA_ID_OUT_OF_RANGE           0x47    //Antenna_id超出范围
#define PARAMETER_INVALID_OUTPUT_POWER_OUT_OF_RANGE         0x48    //输出功率参数超出范围
#define PARAMETER_INVALIDF_FREQUENCY_REGION_OUT_OF_RANGE    0x49    //射频范围区参数超出范围
#define PARAMETER_INVALID_BANDRATE_OUT_OF_RANGE             0x4A    //波特率参数超出范围
#define PARAMETER_BEEPER_MODE_OUT_OF_RANGE                  0x4B    //蜂鸣器设置参数超出范围
#define PARAMETER_EPC_MATCH_LEN_TOO_LONG                    0x4C    //EPC匹配长度越界
#define PARAMETER_EPC_MATCH_LEN_ERROR                       0x4D    //EPC匹配长度错误
#define PARAMETER_INVALID_EPC_MATCH_MODE                    0x4E    //EPC匹配参数超出范围
#define PARAMETER_INVALID_FREQUENCY_RANGE                   0x4F    //频率范围设置参数错误
#define FAIL_TO_GET_RN16_FROM_TAG                           0x50    //无法接收标签的RN16
#define PARAMETER_INVALID_DRM_MODE                          0x51    //DRM设置参数错误
#define PLL_LOCK_FAIL                                       0x52    //PLL不能锁定
#define RF_CHIP_FAIL_TO_RESPONSE                            0x53    //射频芯片无响应
#define FAIL_TO_ACHIEVE_DESIRED_OUTPUT_POWER                0x54    //输出达不到指定的输出功率
#define COPYRIGHT_AUTHENTICATION_FAIL                       0x55    //版权认证未通过
#define SPECTRUM_REGULATION_ERROR                           0x56    //频谱范围设置错误
#define OUTPUT_POWER_TOO_LOW                                0x57    //输出功率过低



#define MAX_RECV_SOCKET_BUFFER  1024*4

#define EPC_MAX_LEN 64
using namespace std;

struct ReaderSetting {
    unsigned char s_btReadId;
    unsigned char s_btMajor;
    unsigned char s_btMinor;
    unsigned char s_btIndexBaudrate;
    unsigned char s_btPlusMinus;
    unsigned char s_btTemperature;
    unsigned char s_btOutputPower;
    unsigned char s_btWorkAntenna;
    unsigned char s_btDrmMode;
    unsigned char s_btRegion;
    unsigned char s_btFrequencyStart;
    unsigned char s_btFrequencyEnd;
    unsigned char s_btBeeperMode;
    unsigned char s_btGpio1Value;
    unsigned char s_btGpio2Value;
    unsigned char s_btGpio3Value;
    unsigned char s_btGpio4Value;
    unsigned char s_btAntDetector;
    unsigned char s_btMonzaStatus;
    string        s_btReaderIdentifier;
    unsigned char s_btAntImpedance;
    unsigned char s_btImpedanceFrequency;

    unsigned char s_nUserDefineStartFrequency;
    unsigned char s_btUserDefineFrequencyInterval;
    unsigned char s_btUserDefineChannelQuantity;
    unsigned char s_btLinkProfile;
};


struct InventoryCount{
    unsigned char workAntId; //此次盘存所用的工作天线
    short         tagCount;  //识别标签的总数量
    short         readRate;  //此次执行命令的标签识别速度，不区分是否多次读取同一张标签
    int           totalRead; //此次执行命令的标签的总读取标签次数， 不区分是否多次读取同一张标签
};

//读取标签返回数据包
struct ReadTagData {
    short           tagCount; //成功操作的标签总数
    unsigned char   dataLen;  //所操作标签的有效数据长度
    unsigned char   data[64]; //所操作标签的有效数据
    unsigned char   readLen;  //read操作的数据长度
    unsigned char   antId;    //
    unsigned char   readCount;//该标签被成功操作的次数
};

struct TagReadBack{
    unsigned char pc[2];
    unsigned char epc[64];
    unsigned char crc[2];
    unsigned char readData[512];
    unsigned char readLen;
    unsigned char dataLen;
    unsigned char epcLen;
    unsigned char workAnt;
    unsigned char readCount;
};

struct CommArg{
    QTcpSocket* m_pTcpSocket;
    int m_Connect;
};

union unShortChar{
    short         sh;
    unsigned char ch[2];
};

union unIntChar{
    int           i;
    unsigned char ch[4];
};

struct EpcData{
    int           epcLen;
    unsigned char freqAnt;
    unsigned char freqPoint;
    unsigned char workAnt;
    unsigned char pc[3];
    unsigned char epc[EPC_MAX_LEN];
    unsigned char rssi;
} ;


//实时盘存标签数据
struct RealInventoryData{
    int             dataType;   //0表示统计数据，1表示标签数据
    InventoryCount  countData;  //统计
    EpcData         epcData;    //epc数据
};
//快速4天线盘存数据
struct FastInventoryData{
    int             dataType;   //0表示统计数据，1表示标签数据
    int             labelTime;  //统计
    int             command;
    EpcData         epcData;     //epc数据
};

typedef struct _MapEpcData
{
    int             id;
    int             epcLen;
    int             totalTimes; //识别次数
    unsigned char   freqPoint;
    unsigned char   pc[3];
    unsigned char   epc[EPC_MAX_LEN];
    unsigned char   rssi;

} MapEpcData;

//数据结构体
typedef struct{
    int id;
    int count;
    string epc;
    string pc;
    unsigned char freqPoint;
    unsigned char rssi;
}Struct_ListEpcText;

//天线轮询设置
struct AntData{
    unsigned char ant;
    unsigned char times;
};

struct FreqRegionDefault{
    unsigned char region;
    unsigned char startFreq;
    unsigned char endFreq;
};

struct FreqRegionCustom{
    unsigned char region; //固定为0x04
    unsigned char freqSpace; //频点间隔为 = freqSpace*10KHz
    unsigned char freqQuantity; //频点数量
    unsigned char startFreq[3];  //单位KHz，16进制高位在前，915000KHz则返回0D F6 38
    int           nstartFreq;    //开始频点
};

struct FreqRegionData{
    int                 type;  //0表示默认频率，1表示用户自定义
    FreqRegionDefault   defaultFreq;
    FreqRegionCustom    customFreq;
};




#endif // STRUCTINTERFACE_H

